import $api from "../../api"
export default {
    namespaced: true,
    state: {
        vips: [

        ],
        total: 0,
        pages: 0,
    },
    mutations: {
        initVip(state, payload) {
            console.log('payload', payload)
            state.vips = payload.vips
            state.total = payload.total
            state.pages = payload.pages
        }
    },
    actions: {
        // 获取所有
        async asyncGetAllVip(context, payload) {
            const res = await $api.vip.getAllVipApi(payload)
            let object = {
                vips: res.data.data,
                total: res.data.data.total,
                pages: res.data.data.pages
            }
            context.commit("initVip", object)
        },
        // 分页获取所有
        async asyncGetAllVipByLimit(context, payload) {
            const res = await $api.vip.getVipByLimit(payload)
            console.log('vip', res)
            let object = {
                vips: res.data.data,
                total: res.data.data.total,
                pages: res.data.data.pages
            }
            context.commit("initVip", object)

           
        },
        // 删除
        async asyncDeleteVip(context, payload) {
            const res = await $api.vip.deleVipById(payload)
            console.log('删除', res.data)
            return res
        },
        // 查询
        async asyncSearchVip(context, payload) {
            const res = await $api.vip.getVipByType(payload)
            console.log('查询', res.data.data)
            let object = {
                vips: res.data.data,
                total: res.data.data.total,
                pages: res.data.data.pages
            }
            context.commit("initVip", object)

        },
        //充值会员
        async asyncUpdateVip(payload) {
            const res = await $api.vip.updateVip(payload)
            console.log('update', res.data)
            console.log('ppp', payload)
            return res

        },
        //取消会员
        async asyncCancleVip(payload) {
            const res = await $api.vip.cancleVip(payload)
            console.log('cc', res.data)
            return res

        }

    }
}